﻿
@{
    ViewBag.Title = "汇总列表";
    Layout = "~/Views/Shared/Master.cshtml";
}

<div class="page-content">
    <!-- BEGIN PAGE HEADER-->
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li>
                <a href="~/Home/Main">首页</a>
                <i class="fa fa-angle-double-right"></i>
            </li>
            <li>
                <a href="#">汇总列表</a>
                <i class="fa fa-angle-double-right"></i>
            </li>
        </ul>
    </div>
    <!-- BEGIN PAGE TITLE-->
    <h3 class="page-title">
        汇总列表
    </h3>
    <!--biaoge-->
    <div class="portlet light">
        <div class="portlet-title">
            <div class="caption"><i class="fa fa-envelope font-yellow-casablanca"></i><span class="caption-subject bold font-yellow-casablanca">汇总列表</span></div>
            @if ((bool)ViewData["IsAdmin"] == false)
            {
                <a class="btn green-meadow kuan" href="javascript:;" onclick="Add();"><i class="fa fa-plus"></i> 添加今日汇总</a>
            }
        </div>
        <!-- END PAGE TITLE-->
        <div class="search_1">
            <form action="~/Home/GetOrder" method="post" id="grform" class="horizontal-form">
                <div class="form-body">
                    <div class="row se_le">
                        <!--/span-->
                        @*<div class="se_pad2">
                            <div class="form-group se_bot">
                                <label class="control-label se_le1">转化率观察方式</label>
                                <div class="se_pad1 padding_le5">
                                    <input type="text" id="UserName" name="UserName" class="form-control" placeholder="子账号名">
                                    <select class="bs-select form-control" id="WatchType" name="WatchType" data-width="125px" style="display:block;">
                                        <option value="0" selected="selected">全部</option>
                                        <option value="1">今日数据</option>
                                        <option value="2">最近一周</option>
                                        <option value="3">最近一月</option>
                                        <option value="4">最近三月</option>

                                    </select>
                                </div>
                            </div>
                        </div>*@
                        <div class="se_pad2">
                            <div class="form-group se_bot">
                                <label class="control-label se_le1">开始时间</label>
                                <div class="se_pad1 padding_le5">
                                    <input type="text" id="CreateTime" name="CreateTime" class="form-control" placeholder="数据结束时间">
                                </div>
                            </div>
                        </div>

                        <div class="se_pad2">
                            <div class="form-group se_bot">
                                <label class="control-label se_le1">结束时间</label>
                                <div class="se_pad1 padding_le5">
                                    <input type="text" id="EndTime" name="EndTime" class="form-control" placeholder="数据结束时间">
                                </div>
                            </div>
                        </div>

                        <!--/span-->
                        @*<div class="se_pad2">
                                <div class="form-group se_bot">
                                    <div class="se_pad1 padding_le5">
                                        <input type="text" id="StartTime" name="StartTime" class="form-control" placeholder="开始时间">
                                    </div>
                                    <div class="se_pad1 padding_le5">
                                        <input type="text" id="EndTime" name="EndTime" class="form-control" placeholder="结束时间">
                                    </div>

                                </div>
                            </div>*@
                        <div class="se_pad2">
                            <div class="form-group se_bot">
                            </div>
                        </div>

                        <div class="cx">
                            <div class="form-group se_bot"><a class="btn btn-primary" onclick="ChaXun();" href="javascript:;"><i class="fa fa-search"></i> 查询</a></div>
                        </div>
                        <div class="cx">
                            <a class="btn default kuan" href="javascript:;" onclick="ExportExcel();"><i class="icon-cloud-upload"></i> 导出</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="portlet-body">
            <div class="table-scrollable_1 table-scrollable-borderless">
                <table class="table table-striped table-hover table-checkable order-column dataTable no-footer table_ri bordered_bott">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>员工</th>
                            <th>加粉数</th>
                            <th>对话数</th>
                            <th>新粉单数</th>
                            <th>老粉单数</th>
                            <th>体验单数</th>
                            <th>体验转正</th>
                            <th>复购</th>
                            <th>数据总量</th>
                            <th>新粉转化率</th>
                            <th>体验装转化率</th>
                            <th>转正率</th>
                            <th>复购率</th>
                            <th>老粉转化率</th>
                            <th>整体转化率</th>
                        </tr>
                    </thead>
                    <tbody id="tbody"></tbody>
                </table>
                <div style="margin-bottom:50px;" id="fenye">
                    <button class="layui-btn layui-btn-xs" style="float:left" onclick="LastPage();">上一页</button>
                    <div style="padding:inherit;float:left;width:78px;height:38px;"><div style="margin-top:8px;text-align:center;" id="pagecounttext"></div></div>
                    <button class="layui-btn layui-btn-xs" style="float:left" onclick="NextPage();">下一页</button>
                    <div style="height:38px;width:500px;float:left;">
                        <div><span style="float:left;margin-left:10px;margin-top:8px;">跳转至</span></div>
                        <div style="height:38px;">
                            <input type="text" id="pagecount" style="margin-left:20px;margin-top:7px; width:50px;" />
                            <button class="" style="margin-left:20px;margin-top:7px; width:50px;" onclick="JumpPage();">确定</button>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

<link href="~/Scripts/layui/css/layui.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/layui/layui.js"></script>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#CreateTime  ' //指定元素
        });
        laydate.render({
            elem: '#EndTime  ' //指定元素
        });
    });
</script>
<script>
    var pageindex = 1;
    var pagecount;
    $(function () {
        pageindex = 1;
        GetPage();
    });
    function GetPage() {
        $.ajax({
            url: "/Home/GetSummaryPage",
            data: {
                pageindex: pageindex,
                WatchType: $("#WatchType").val(),
                CreateTime: $("#CreateTime").val(),
                EndTime: $("#EndTime").val()
            },
            type: "post",
            success: function (result) {
                if (result.totalcount > 0) {
                    var str = ToHtml(result.list);
                    $("#tbody").html('');
                    $("#tbody").html(str);
                    $("#pagecounttext").text(pageindex + "/" + result.pagecount);
                    pagecount = result.pagecount;
                    $("#fenye").show();
                } else {
                    if (result.success == true) {
                        $("#tbody").html('暂无数据');
                        $("#fenye").hide();
                    } else {
                        layer.msg(result.msg, { icon: 2 });
                    }
                }
            }
        });
    }
    function ChaXun() {
        pageindex = 1;
        GetPage();
    }
    function LastPage() {
        if (pageindex > 1) {
            pageindex--;
            GetPage();
        }
    }
    function NextPage() {
        if (pageindex < pagecount) {
            pageindex++;
            GetPage();
        }
    }
    function JumpPage() {
        var c = $("#pagecount").val();
        if (!isNaN(c) && c >= 1 && c <= pagecount) {
            pageindex = c;
            GetPage();
        }
    }

    function ToHtml(data) {
        var str = "";
        $.each(data, function (i, item) {
            str += "<tr><td>" + (i + 1) + "</td>";
            str += "<td>" + item.UserName + "</td>";
            str += "<td>" + item.TodayFansNum + "</td>";
            str += "<td>" + item.TodayTalkNum + "</td>";
            str += "<td>" + item.NewFansOrderNum + "</td>";
            str += "<td>" + item.OldFansOrderNum + "</td>";
            str += "<td>" + item.SampleOrderNum + "</td>";
            str += "<td>" + item.SampleToforMalOrderNum + "</td>";
            str += "<td>" + item.RePurchaseOrderNum + "</td>";
            str += "<td>" + item.TodaySumNum + "</td>";
            str += "<td>" + item.xfzhl + "</td>";
            str += "<td>" + item.tyzzhl + "</td>";
            str += "<td>" + item.zzl + "</td>";
            str += "<td>" + item.fgl + "</td>";
            str += "<td>" + item.lfzhl + "</td>";
            str += "<td>" + item.ztzhl + "</td></tr>";
        })
        return str;
    }



    function ExportExcel() {
        $.ajax({
            url: "/Home/ExportExcelSummary",
            data: {
                WatchType: $("#WatchType").val(),
                CreateTime: $("#CreateTime").val(),
                EndTime: $("#EndTime").val()
            },
            success: function (result) {
                if (result.success) {
                    window.open(result.url);
                } else {
                    layer.msg(result.msg, { icon: 2 });
                }
            }
        });
    }

    //function Update(id) {
    //    window.location.href = "/Home/SummaryEdit?id=" + id;
    //}

    //function Add() {
    //    window.location.href = "/Home/SummaryEdit";
    //}

</script>